/*
 *@author  chengkenli
 *@project setbuckets
 *@package service
 *@file    ScanSchemaAutoSetBuckets
 *@date    2024/8/2 9:40
 */

package service

import (
    "StarRocksBuckets/tools"
    "StarRocksBuckets/util"
    "strings"
    "sync"
)

// ScanSchemaAutoSetBuckets 自动分桶设置
func ScanSchemaAutoSetBuckets() {

    ch := make(chan struct{}, util.Thread)
    var wg sync.WaitGroup
    for _, table := range strings.Split(util.Table, ",") {
        wg.Add(1)

        go func(table string) {
            defer func() {
                <-ch
                wg.Done()
            }()

            ch <- struct{}{}
            bucketInfo := tools.GetBuckets(table)
            ScanSchemaSetBuckets(table, int64(bucketInfo.Best))
        }(table)
    }
    wg.Wait()
}
